# -*- coding: utf-8 -*-

import logging
import json

from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from django.db.models.fields.related import RelatedField
from django.forms import model_to_dict
from rest_framework.authentication import BaseAuthentication, SessionAuthentication

from rest_framework.exceptions import AuthenticationFailed

logger = logging.getLogger(__name__)


class CustomAuthentication(BaseAuthentication):

    def authenticate(self, request):
        logger.info('authenticate')
        # token = request._request.GET.get('token')
        # if not token:
        #     raise AuthenticationFailed('AuthenticationFailed')
        user = get_user_model().objects.filter(username='admin').first()
        return user, None

    def authenticate_header(self, request):
        logger.info('authenticate_header')
        super().authenticate_header(request)


class CustomSessionAuthentication(SessionAuthentication):

    def enforce_csrf(self, request):
        return

    def authenticate_header(self, request):
        return 'sessionid'
